package com.ittx.dzt.shein.service.semi;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.ittx.dzt.edi.constant.PlatformMessageConstant;
import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.edi.dto.StoreConfigDTO;
import com.ittx.dzt.edi.vo.ResponseMessageVO;
import com.ittx.dzt.shein.handler.AbstractBaseSheinSemiApiHandler;
import com.ittx.dzt.sys.response.Result;
import lombok.extern.slf4j.Slf4j;
import open.constant.PlatformApiConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 查询仓库地址
 * <p>
 *	cy.shipment.query.warehouse.address
 * /open-api/gsp/warehouse-address 查询仓库地址 https://open.sheincorp.com/zh/documents/apidoc/detail/3001321
 * </p>
 *
 * @author wl_code@163.com
 * @version 1.0
 * @date 2025/8/1
 */
@Slf4j
@Service
public class SheinSemiQueryWarehouseAddressService extends AbstractBaseSheinSemiApiHandler<String> {

	@Override
	public String getSheinSemiMethod() {
		return "/open-api/gsp/warehouse-address";
	}

	@Override
	public String getLocalApiMethod() {
		return PlatformApiConstant.InboundInterface.SHIPMENT_QUERY_WAREHOUSE_ADDRESS;
	}

	@Override
	public Result<?> doProcess(PlatformApiParamDTO platformApiParamDTO, String orderNo) {
		Map<String, Object> params = new HashMap<>();
		StoreConfigDTO storeConfig = platformApiParamDTO.getStoreConfig();
		String requestId = platformApiParamDTO.getRequestId();
		Result<?> result = this.executeApi(storeConfig, params, requestId);
		if (result.hasError()) {
			return result;
		}
		Map<String, Object> resultMap = (Map<String, Object>) result.getData();
		Map<String, Object> addressInfo = (Map<String, Object>) resultMap.get(DATA_FIELD);
		if (MapUtil.isEmpty(addressInfo)) {
			String msg = StrUtil.format(PlatformMessageConstant.MSG_PLAT_0018, requestId, orderNo);
			log.error(msg);
			return Result.error(new ResponseMessageVO(PlatformMessageConstant.MSG_PLAT_0018, msg));
		}
		return Result.success().addData(addressInfo);
	}
}
